import random
import string
import ddddocr
import os
import time
from selenium import webdriver

def getcode(driver,id):
    p_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    t = time.time()
    pic_path = pic_path = p_path + '\\' + 'screenshots' + '\\' +  str(t) + '.png'
    driver.find_element_by_id(id).screenshot(pic_path)
    ocr = ddddocr.DdddOcr()
    with open(pic_path, 'rb') as f:
        img_bytes = f.read()
    res = ocr.classification(img_bytes)
    print('本次验证码：',res)

    return res

def gen_random_str():
    random_str = ''.join(random.sample(string.ascii_letters + string.digits,8))
    return random_str

